import { defineStore } from 'pinia'
import { ref } from 'vue'
import {userGetInfoService} from '@/api/user.js'
// 定义token，setToken，removeToken

export const useUserStore = defineStore('big-user', () => {
  const token = ref('失败')

  // 正确的函数声明
  const setToken = (newToken) => {
    token.value = newToken
  }

  const removeToken = () => {
    token.value = ''
  }

	//封装用户信息
	const user=ref({})
	const getUser=async()=>{
		const res=await userGetInfoService()
		// console.log(res);
		//res.data是本身ref语法
		//res.data.data是该user对象
		user.value=res.data.data
	}
	
	const setUser=(obj)=>{
		user.value=obj
	}
  // 暴露出去
  return {
    token,
    setToken,
    removeToken,
		getUser,
		setUser
  }
},{
	persist:true
})
